package com.bfl.mybatis.generator;

import org.mybatis.generator.exception.ShellException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;

public class CustomShellCallback extends DefaultShellCallback {
    /**
     * Instantiates a new default shell callback.
     *
     * @param overwrite the overwrite
     */
    public CustomShellCallback(boolean overwrite) {
        super(overwrite);
    }

    @Override
    public File getDirectory(String targetProject, String targetPackage) throws ShellException {

        File project = new File(targetProject);
        if (!project.isDirectory()) {
            // idea 找不到 src目录，
            String path = CustomShellCallback.class.getClassLoader().getResource("").getPath();
            targetProject = path + ".." + File.separator + ".." + File.separator + targetProject;
        }

        return super.getDirectory(targetProject, targetPackage);
    }
}
